package com.hrm;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.hrm.dao.GroupsMapper;
import com.hrm.dao.PeopleMapper;
import com.hrm.entity.Groups;
import com.hrm.entity.People;

public class TestPeople {
	static SqlSession session=null;
	static{
		 //读取spring配置文件
        BeanFactory beanFactory = new ClassPathXmlApplicationContext(
                "spring.xml");
        //通过spring配置文件生成的beanFactory获得SqlSessionFactory
        SqlSessionFactory factory = (SqlSessionFactory) beanFactory
                .getBean("sqlSessionFactory");
        //获得SqlSession
        session = factory.openSession();
	}
	public List<People> getAllPeople(){
		PeopleMapper pMapper = session.getMapper(PeopleMapper.class);
		return pMapper.selectAllPeople();
	}
	public People getPeopleByPId(int pid){
		PeopleMapper pMapper = session.getMapper(PeopleMapper.class);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("pid", pid);
		return pMapper.selectPeopleByMap(map).get(0);
	}
	public List<Groups> getAllGroups(){
		GroupsMapper gMapper = session.getMapper(GroupsMapper.class);
		return gMapper.selectAllGroups();
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		TestPeople tPeople = new TestPeople();
//		System.out.println(tPeople.getAllPeople());
//		System.out.println(tPeople.getAllGroups());
		System.out.println(tPeople.getPeopleByPId(10000));
		System.out.println(tPeople.getPeopleByPId(10000).toJSONString());
	}

}
